package encrypt.demo;

import cn.hutool.crypto.asymmetric.SM2;
import cn.hutool.crypto.asymmetric.KeyType;

import java.util.Date;

public class SM2Demo {
    public static void main(String[] args) {
        long init_begin = new Date().getTime();
        // 生成 SM2 密钥对
        SM2 sm2 = new SM2();
        long init_end = new Date().getTime();
        System.out.println(init_end-init_begin);


        long en_begin = new Date().getTime();
        // 加密
        String data = "Hello, world!";
        String encryptStr = sm2.encryptBase64(data, KeyType.PublicKey);
//        for (int i = 0; i < 100; i++) {
//            sm2.encryptBase64(data+i,KeyType.PublicKey);
//        }
        long en_end = new Date().getTime();
        System.out.println(en_end-en_begin);
        System.out.println(encryptStr);
        long de_begin = new Date().getTime();

        //解密
        String decryptStr = sm2.decryptStr(encryptStr, KeyType.PrivateKey);
        long de_end = new Date().getTime();
        System.out.println(de_end-de_begin);
        System.out.println(decryptStr); // 输出 "Hello, world!"

    }
}
